package com.ruoyi.system.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.utils.FileDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CollectRuleMapper;
import com.ruoyi.system.domain.CollectRule;
import com.ruoyi.system.service.ICollectRuleService;

import javax.annotation.Resource;

/**
 * 采集规则Service业务层处理
 *
 * @author chenming
 * @date 2024-10-16
 */
@Service
public class CollectRuleServiceImpl extends ServiceImpl<CollectRuleMapper, CollectRule> implements ICollectRuleService
{
    @Resource
    private CollectRuleMapper collectRuleMapper;

    /**
     * 查询采集规则
     *
     * @param collectId 采集规则主键
     * @return 采集规则
     */
    @Override
    public CollectRule selectCollectRuleByCollectId(Long collectId)
    {
        return collectRuleMapper.selectCollectRuleByCollectId(collectId);
    }

    /**
     * 查询采集规则列表
     *
     * @param collectRule 采集规则
     * @return 采集规则
     */
    @Override
    public List<CollectRule> selectCollectRuleList(CollectRule collectRule)
    {
        return collectRuleMapper.selectCollectRuleList(collectRule);
    }

    /**
     * 新增采集规则
     *
     * @param collectRule 采集规则
     * @return 结果
     */
    @Override
    public int insertCollectRule(CollectRule collectRule)
    {
        return collectRuleMapper.insertCollectRule(collectRule);
    }

    /**
     * 修改采集规则
     *
     * @param collectRule 采集规则
     * @return 结果
     */
    @Override
    public int updateCollectRule(CollectRule collectRule)
    {
        int i = collectRuleMapper.updateCollectRule(collectRule);
        // 更新模板
        FileDataUtils.removeFile(collectRule.getCollectName()+".py");
        return i;
    }

    /**
     * 批量删除采集规则
     *
     * @param collectIds 需要删除的采集规则主键
     * @return 结果
     */
    @Override
    public int deleteCollectRuleByCollectIds(Long[] collectIds)
    {
        return collectRuleMapper.deleteCollectRuleByCollectIds(collectIds);
    }

    /**
     * 删除采集规则信息
     *
     * @param collectId 采集规则主键
     * @return 结果
     */
    @Override
    public int deleteCollectRuleByCollectId(Long collectId)
    {
        return collectRuleMapper.deleteCollectRuleByCollectId(collectId);
    }
}
